# Importing Data
USA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Aluminium/Aluminium.xlsx",sheet = "Sheet1", range = "AJ1:AJ264")

# Checking the Imported Data
View(USA)
# Creating Time Series Data
USA_ts <- ts(USA, start=c(1998,1), end=c(2018,5), frequency=12)
# Viewing and Checking the Created Time Series Data
USA_ts
sum(is.na(USA_ts))
library(forecast)
USA_ts <- tsclean(USA_ts)
USA_ts

# Identification: Plotting the Time Series Data
plot(USA_ts)

# Estimating the appropriate model
USA_ts_model <- auto.arima(USA_ts)
USA_ts_model

# Forecasting
options(max.print=1000000)
USA_ts_forecast <- forecast (USA_ts_model, level=c(95), h=371)
plot(USA_ts_forecast)
USA_ts_forecast             

# Exporting
write.table(USA_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Aluminium/USA_TSA.csv", sep=",")
